<?php
use app\models\Mall;
use app\widgets\MallMBottomToolbarWidget;
use yii\helpers\Url;

$web = Url::base();

$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$institution_code = Mall::getCurrentInstitutionCode();
$this->title = $site_name . '-商品搜索';
?>

<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/search.css"/>

<div class="main">
    <div class="header">
        <div class="search">
            <img src="<?= $web ?>/images/mall-m/index-icon-search.png">
            <input id="inputSearch" type="text" placeholder="搜索  商品名称"/>
        </div>
        <a id="btnCancel" href="#">
            <div class="button btn-cancel">
                <p>取消</p>
            </div>
        </a>
        <a id="btnSearch" href="#" style="display: none;">
            <div class="button btn-search">
                <p>搜索</p>
            </div>
        </a>
    </div>
    <div class="interval">
        <div class="heade">
            <p class="section f-l">积分区间</p>
            <?php
                if($userIntegral!=null){
                    ?>
                    <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>0,'integralTo'=>intval($userIntegral),'sort'=>2,'institution_code' => $institution_code])?>">
                        <p class="convert f-r">我能兑换</p>
                    </a>
                    <?php
                }
            ?>

        </div>
        <div class="interval-group">
            <ul>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>0,'integralTo'=>50,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-1">0-50</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>50,'integralTo'=>100,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">50-100</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>100,'integralTo'=>200,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">100-200</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>200,'integralTo'=>300,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-3">200-300</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>300,'integralTo'=>400,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-1">300-400</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>400,'integralTo'=>500,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">400-500</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>500,'integralTo'=>600,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">500-600</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>600,'integralTo'=>700,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-3">600-700</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>700,'integralTo'=>800,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-1">700-800</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>800,'integralTo'=>900,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">800-900</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>900,'integralTo'=>1000,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-2">900-1000</li>
                </a>
                <a href="<?=Url::to(['mall-m/goods-list','integralFrom'=>1000,'sort'=>2,'institution_code' => $institution_code])?>">
                    <li class="interval-group-3">1000以上</li>
                </a>
            </ul>
        </div>
        <div class="hunt">
            <input class="minimum" type="number" value="" placeholder="最低积分" />
            <div class="hunt-line"></div>
            <input class="highest" type="number" value="" placeholder="最高积分" />
            <a class="ensure-btn" href="javascript:hrefGoodsListByIntegral()">确定</a>
        </div>
        <div class="boundary"></div>
        <div class="hot-seek">
            <p class="title">热门搜索</p>
            <div class="hot-seek-list">
                <ul>
                    <a href="">
                        <li>大闸蟹</li>
                    </a>
                    <a href="">
                        <li>刀</li>
                    </a>
                    <a href="">
                        <li>压力锅</li>
                    </a>
                    <a href="">
                        <li>罗比罗丹</li>
                    </a>
                    <a href="">
                        <li>菲米生活</li>
                    </a>
                    <a href="">
                        <li>美的</li>
                    </a>
                    <a href="">
                        <li>惠而浦</li>
                    </a>

                </ul>
            </div>
        </div>
    </div>
    <?=MallMBottomToolbarWidget::widget(['actionName'=>''])?>
</div>

<script type="application/javascript">
    $(function() {
        $('#inputSearch').on('input', function(){
            if($(this).val().length>0){
                $('#btnCancel').hide();
                $('#btnSearch').show();
            }else{
                $('#btnCancel').show();
                $('#btnSearch').hide();
            }
        });

//        $("#inputSearch").focus();
        $('#inputSearch').bind('keypress',function(event){
            if(event.keyCode == "13") {
                var findStr=$('#inputSearch').val();
                hrefGoodsListByGoodsName(findStr);
            }
        });
        $('#btnSearch').click(function(){
            var findStr=$('#inputSearch').val();
            hrefGoodsListByGoodsName(findStr);

        });

        $('.hot-seek-list a').click(function(){
            var findStr=$(this).find('li').html();
            hrefGoodsListByGoodsName(findStr);
            return false;
        });
    });
    hrefGoodsListByGoodsName=function(findStr){
        var link_url="<?=Url::to(['mall-m/goods-list','institution_code'=>$institution_code])?>";
        window.location.href=link_url+"&goodsName="+encodeURIComponent(findStr)+"&goodsListTitle="+encodeURIComponent("商品搜索："+findStr);
    };
    hrefGoodsListByIntegral =function(){
        var integralFrom=parseInt($('.minimum').val());
        var integralTo=parseInt($('.highest').val());
        if(isNaN(integralFrom)){
            integralFrom=0;
        }
        if(isNaN(integralTo)){
            integralTo=0;
        }
        var link_url="<?=Url::to(['mall-m/goods-list','institution_code'=>$institution_code,'sort'=>2])?>";
        window.location.href=link_url+"&integralFrom="+integralFrom+"&integralTo="+integralTo;
    };
</script>
